package net.mikoo.seals.api.model.seal;

import org.apache.commons.lang.StringUtils;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.common.enums.SealStatusEnum;
import net.mikoo.seals.model.Seal;

public class SealDetailResponse extends BaseResponse {

	private static final long serialVersionUID = 1L;

	private SealInfo sealInfo;

	public SealInfo getSealInfo() {
		return sealInfo;
	}

	public void setSealInfo(SealInfo sealInfo) {
		this.sealInfo = sealInfo;
	}
	
	public static SealDetailResponse valueOf(Seal seal) {
		SealDetailResponse result = new SealDetailResponse();
		
		if(seal == null) {
			return result;
		}
		
		SealInfo sealInfo = new SealInfo();
		sealInfo.setSealId(seal.getSealId());
		sealInfo.setSealName(seal.getSealName());
		if(StringUtils.isNotBlank(seal.getSealName())) {
			sealInfo.setIconText(seal.getSealName().substring(0, seal.getSealName().length() < 2 ? 1 : 2));
		}
		sealInfo.setCustosPartyName(seal.getCustosName());
		sealInfo.setDevicesNum(seal.getDevicesList().size());
		
		sealInfo.setCustosPartyId(seal.getPartyId());
		sealInfo.setLimitUrgentApply(seal.getLimitUrgentApply());
		
		SealStatusEnum sealStatus = SealStatusEnum.getByCode(seal.getSealStatus());
		if(sealStatus != null) {
			sealInfo.setStatus(sealStatus.getCode());
			sealInfo.setStatusName(sealStatus.getMessage());
		}
		
		result.setSealInfo(sealInfo);
		return result;
	}
	
}
